home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / libkb100.zip / LIBKB-1.00 / SRC / _KB.H < prev    next >
C/C++ Source or Header  |  1996-07-23  |  8KB  |  286 lines

  1. /* _kb.h -- include file used for building 'libkb'
  2.  * Copyright (C) 1995, 1996 Markus F.X.J. Oberhumer
  3.  * For conditions of distribution and use, see copyright notice in kb.h 
  4.  */
  5.  
  6. /* WARNING: this file should *not* be used by applications. It is
  7.    part of the implementation of the keyboard library and is
  8.    subject to change. Applications should only use kb.h.
  9.  */
  10.  
  11.  
  12. #ifndef __LIBKB_KB_INTERNAL_H
  13. #define __LIBKB_KB_INTERNAL_H
  14.  
  15.  
  16. /* memory locking */
  17. #if defined(__KB_MSDOS32)
  18. #  if defined(__DJGPP__) || defined(__WATCOMC__)
  19. #    include <kbmlock.h>
  20. #  endif
  21. #endif
  22.  
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. #if !defined(__inline__) && !defined(__GNUC__)
  29. #  if defined(__cplusplus)
  30. #    define __inline__        inline
  31. #  else
  32. #    define __inline__        /* nothing */
  33. #  endif
  34. #endif
  35.  
  36. /* make KB_DEBUG numeric if defined */
  37. #if defined(KB_DEBUG) && (KB_DEBUG < 1)
  38. #  undef KB_DEBUG
  39. #  define KB_DEBUG    1
  40. #endif
  41.  
  42. /* exit code for a signal */
  43. #define EXIT_SIG(signum)    (128 + ((signum) & 0x7f))
  44.  
  45. #ifndef HIGH
  46. #  define HIGH(x)        ((int)(sizeof(x)/sizeof(*(x))))
  47. #endif
  48.  
  49.  
  50. /***********************************************************************
  51. // virtual keys and shift-states for internal use
  52. ************************************************************************/
  53.  
  54. #define KB_SCAN_UNKNOWN                 0     /* internal - must be 0 */
  55. #define KB_SCAN_MAX_RAW                 0x5d  /* 0x5d -> KB_SCAN_RMENU */
  56.  
  57. #define KB_SCAN_CONTROL_BREAK_VIRTUAL   101   /* 0x65 - Linux */
  58. #define KB_SCAN_PAUSE_VIRTUAL           119   /* 0x77 - Linux */
  59.  
  60. /* hopefully the next code doesn't exist on an exotic keyboard... */
  61. #define KB_SCAN_UNUSED_VIRTUAL          120   /* 0x78 */
  62.  
  63.  
  64. #define KB_SHIFT_NO_PRESS       0x4000   /* do not generate a key press */
  65. #define KB_SHIFT_VIRTUAL        0x8000   /* one of the virtual keys above */
  66.  
  67. #define KB_SHIFT_MASK_SHIFT     0x003f   /* mask for a 'normal' shift flag */
  68. #define KB_SHIFT_MASK_TOGGLE    0x0fc0   /* mask for a toggle flag */
  69.  
  70.  
  71. /***********************************************************************
  72. // internal tables
  73. ************************************************************************/
  74.  
  75. extern const unsigned char _kb_prefix_scancode[128];
  76. /**** extern const unsigned char _kb_inverse_prefix_scancode[128]; */
  77.  
  78. extern const unsigned short _kb_shift_state_table[128];
  79. /**** extern const unsigned short _kb_unshift_state_table[128]; */
  80.  
  81. #if 0
  82. extern unsigned short _kb_plain_table[128];
  83. extern unsigned short _kb_shift_table[128];
  84. extern unsigned short _kb_alt_table[128];
  85. extern unsigned short _kb_control_table[128];
  86. #else
  87. /* these are static const tables now */
  88. #define _kb_plain_table        default_plain_table
  89. #define _kb_shift_table        default_shift_table
  90. #define _kb_alt_table        default_alt_table
  91. #define _kb_control_table    default_control_table
  92. #endif
  93.  
  94. void _kb_init_tables(void);
  95.  
  96. extern const unsigned kb_version_id;
  97. extern const char kb_version_string[];
  98. extern const char kb_version_date[];
  99. extern const char kb_copyright[];
  100.  
  101.  
  102. /***********************************************************************
  103. // locking - this is very important under MSDOS + DPMI
  104. ************************************************************************/
  105.  
  106. /* one lock function for each source file */
  107. int _libkb_kbhandle_lock(void);
  108. int _libkb_kbmlock_lock(void);
  109. int _libkb_kbos_lock(void);
  110. int _libkb_kbsignal_lock(void);
  111. int _libkb_kbtables_lock(void);
  112.  
  113. /* main lock function */
  114. int _kb_lock(void);
  115. void _kb_unlock(void);
  116.  
  117.  
  118. /***********************************************************************
  119. // misc.
  120. ************************************************************************/
  121.  
  122. int _kb_signal_install(void);
  123. int _kb_signal_lock(void);
  124.  
  125. int _kb_signal_alarm_install(void);
  126. void _kb_signal_alarm_update(void);
  127.  
  128. void _kb_emergency_remove(int final);
  129.  
  130.  
  131. #if defined(__KB_LINUX)
  132.  
  133. int _kb_linux_switch_vt(int fd, int vt);
  134. int _kb_linux_is_switch(int *vt, int vtnum1, int vtnum2);
  135. int _kb_linux_update(const unsigned char *buf, int len, 
  136.                      void (*key_handler)(unsigned char));
  137.  
  138. #endif
  139.  
  140.  
  141. /***********************************************************************
  142. // BIOS keyboard access
  143. ************************************************************************/
  144.  
  145. #if defined(__KB_MSDOS)
  146.  
  147. /* cmd values for kb_bioskey() */
  148. #define KB_KEYBRD_READ              0       /* read key */
  149. #define KB_NKEYBRD_READ             0x10    /* read key - enhanced */
  150. #define KB_KEYBRD_READY             1       /* check key ready */
  151. #define KB_NKEYBRD_READY            0x11    /* check key ready - enhanced */
  152. #define KB_KEYBRD_SHIFTSTATUS       2       /* get shift status */
  153. #define KB_NKEYBRD_SHIFTSTATUS      0x12    /* get shift status - enhanced */
  154.  
  155. #endif
  156.  
  157. int kb_bioskey(unsigned _cmd);
  158.  
  159.  
  160. /***********************************************************************
  161. // low level includes and defines
  162. ************************************************************************/
  163.  
  164. #if (defined(__BORLANDC__) || defined(__TURBOC__)) && defined(__MSDOS__)
  165. #  include <dos.h>
  166. #  include <bios.h>
  167. #  define KB_DISABLE()        disable()
  168. #  define KB_ENABLE()        enable()
  169. #  define KB_INP8(a)        inportb(a)
  170. #  define KB_OUTP8(a,b)        outportb(a,b)
  171. #  define KB_INT86_REGS        union REGS
  172. #  define KB_INT86(n,r)        int86(n,r,r)
  173. #elif defined(__EMX__)
  174. #  include <dos.h>
  175. #  include <sys/hw.h>
  176. #  include <os2.h>
  177. #  if 1
  178. #    define KB_DISABLE()    /* not allowed under emx */
  179. #    define KB_ENABLE()        /* not allowed under emx */
  180. #  else
  181. #    define KB_DISABLE()    __asm__ __volatile__("cli \n")
  182. #    define KB_ENABLE()        __asm__ __volatile__("sti \n" "cld \n")
  183. #  endif
  184. #  define KB_INP8(a)        _inp8(a)
  185. #  define KB_OUTP8(a,b)        _outp8(a,b)
  186. #  define KB_INT86_REGS        union REGS
  187. #  define KB_INT86(n,r)        _int86(n,r,r)
  188. #  define KB_USE_INT86() \
  189.         (_osmode == DOS_MODE && (_emx_env & 0x0800))    /* _int86() allowed ? */
  190. #elif defined(__DJGPP__)
  191. #  if !defined(__GO32__)
  192. #    error check your djgpp configuration
  193. #  endif
  194. #  include <dos.h>
  195. #  include <bios.h>
  196. #  include <dpmi.h>
  197. #  include <go32.h>
  198. #  include <pc.h>
  199. #  include <unistd.h>
  200. #  if 1
  201. #    define KB_DISABLE()    __asm__ __volatile__("cli \n")
  202. #    define KB_ENABLE()        __asm__ __volatile__("sti \n" "cld \n")
  203. #  else
  204.      /* don't use this - makes problems in a Windows 3.1 DOS box ! */
  205. #    define KB_DISABLE()    __dpmi_get_and_disable_virtual_interrupt_state()
  206. #    define KB_ENABLE()     __dpmi_get_and_enable_virtual_interrupt_state()
  207. #  endif
  208. #  define KB_INP8(a)        inportb(a)
  209. #  define KB_OUTP8(a,b)        outportb(a,b)
  210. #  define KB_INT86_REGS        __dpmi_regs
  211. #  define KB_INT86(n,r)        __dpmi_int(n,r)
  212. #elif defined(__GO32__)
  213. #  include <dos.h>
  214. #  include <bios.h>
  215. #  include <dpmi.h>
  216. #  include <go32.h>
  217. #  include <pc.h>
  218. #  define _KB_NO_SIGNALS    /* djgpp v1 has no useable signals */
  219. #  define KB_DISABLE()        disable()
  220. #  define KB_ENABLE()        enable()
  221. #  define KB_INP8(a)        inportb(a)
  222. #  define KB_OUTP8(a,b)        outportb(a,b)
  223. #  define KB_INT86_REGS        union REGS
  224. #  define KB_INT86(n,r)        int86(n,r,r)
  225. #elif defined(_MSC_VER) && defined(MSDOS)
  226. #  include <dos.h>
  227. #  include <bios.h>
  228. #  define KB_DISABLE()        disable()
  229. #  define KB_ENABLE()        enable()
  230. #  define KB_INP8(a)        inp(a)
  231. #  define KB_OUTP8(a,b)        outp(a,b)
  232. #  define KB_INT86_REGS        union REGS
  233. #  define KB_INT86(n,r)        int86(n,r,r)
  234. #elif defined(__WATCOMC__) && defined(MSDOS)
  235. #  include <dos.h>
  236. #  include <bios.h>
  237. #  include <i86.h>
  238. #  define KB_DISABLE()        _disable()
  239. #  define KB_ENABLE()        _enable()
  240. #  define KB_INP8(a)        inp(a)
  241. #  define KB_OUTP8(a,b)        outp(a,b)
  242. #  define KB_INT86_REGS        union REGPACK
  243. #  define KB_INT86(n,r)        intr(n,r)
  244. #elif defined(__KB_LINUX)
  245. #  include <unistd.h>
  246. #  define KB_INP8(a)        /* nothing */
  247. #  define KB_OUTP8(a,b)        /* nothing */
  248. #  if 1
  249. #    define KB_DISABLE()    /* not allowed and not needed under Linux */
  250. #    define KB_ENABLE()        /* not allowed and not needed under Linux */
  251. #  else
  252. #    include <asm/system.h>    /* probably only legal for kernel building */
  253. #    define KB_DISABLE()    cli()
  254. #    define KB_ENABLE()        sti()
  255. #  endif
  256. #  define KB_SIGNAME(n)        (_sys_siglist[n])
  257. #else
  258. #  error unsupported compiler
  259. #endif
  260.  
  261. #if !defined(KB_DISABLE)
  262. #  define KB_DISABLE()        /* nothing */
  263. #endif
  264. #if !defined(KB_ENABLE)
  265. #  define KB_ENABLE()        /* nothing */
  266. #endif
  267.  
  268.  
  269. #if defined(KB_INT